package cn.hdustea.shopNavigation.ui.view.bottom.mine

import android.annotation.SuppressLint
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import cn.hdustea.shopNavigation.R
import cn.hdustea.shopNavigation.config.ConfigKey
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import kotlinx.android.synthetic.main.fragment_mine.*

/**
 * <pre>
 *     author : HuQiang
 *     time   : 2020/09/18
 *     desc   :
 *     version: 1.0
 * </pre>
 */
class MineFragment : Fragment() {

    companion object {
        fun getInstance(): MineFragment = MineFragment()
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_mine, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        //设置
        layout_setting.setOnClickListener {
            if (context != null) {
                SettingActivity.startActivity(context!!)
            }
        }
    }

    @SuppressLint("SetTextI18n")
    override fun onResume() {
        super.onResume()
        tv_name.text = ConfigKey.getUserName()
        val phone = ConfigKey.getUserPhone()
        if (!TextUtils.isEmpty(phone)) {
            tv_phone_num.text = phone.substring(0, 3) + "****" + phone.substring(7, 11)
        }
        val options: RequestOptions = RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                .circleCrop()
                .dontAnimate()

        Glide.with(this).load(ConfigKey.getUserPortrait())
                .apply(options)
                .into(im_portrait)
    }
}